package leetcode.editor.offer;

// 剑指 Offer 64. 求1+2+…+n
// https://leetcode.cn/problems/qiu-12n-lcof/
class Qiu12nLcof {
    public static void main(String[] args) {
        Solution solution = new Qiu12nLcof().new Solution();
        solution.sumNums(3);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        int sum = 0;

        public int sumNums(int n) {
            // 不能使用if，可以使用 && 符号终止递归，此时如果 n==0 之后，就不再递归
            boolean b = n > 0 && sumNums(n - 1) > 0;
            sum += n;
            return sum;
        }

    }
//leetcode submit region end(Prohibit modification and deletion)

}
